package com.vframework.common.service;

import java.util.ArrayList;
import java.util.List;

import com.vframework.base.model.BaseBean;
import com.vframework.common.constant.GlobalConstant;
import com.vframework.common.model.RegionsBean;
/***************************************************************
 * Name:        DictService.java
 * Create At:   2018年4月18日
 * Module:      
 * Description: [系统管理-从字典表获取下拉框值]
 * @author      shanzhitong
 * ------------------------------------------------------------
 * 修改历史
 * 序号         日期                       修改人               修改原因
 * 1    2018年4月18日      shanzhitong    
 * 2
***************************************************************/
public class DictService {

    /**
	 * Author:shanzhitong
     * Create At:2013-01-05
     * Description: [根据类型和编码获取有效的字典数据]
     * type 类型
     * status 状态
     * Condition 指定编码
     * @return String
     */
    public static String getTypeList(String type, String status,String Condition) {
    	String str = "";
    	if(GlobalConstant.DICT_LIST != null && type != null && !"".equals(type.trim()) && status != null){
    		for(BaseBean dict:GlobalConstant.DICT_LIST){
    			if(type.equals(dict.getPcode()) &&  status.equals(dict.getStatus()) && Condition.equals(dict.getCode())){
    				str = dict.getName();
    			}
    		}
    	}
		return str;
    }
    /**
	 * Author:shanzhitong
     * Create At:2010-06-22
     * Description: [根据类型获取下拉列表 有效或无效的都获取]
     * @return String
     */
    public static List<BaseBean> getTypeList(String type) {
    	List<BaseBean> list = new ArrayList<BaseBean>();
    	if(GlobalConstant.DICT_LIST != null && type != null && !"".equals(type.trim())){
    		for(BaseBean dict:GlobalConstant.DICT_LIST){
    			if(type.equals(dict.getPcode())){
    				list.add(dict);
    			}
    		}
    	}
		return list;
    }
    
    /**
     * Author:shanzhitong
     * Create At:2017-05-07
     * Description: [根据类型和默认值获取名称]
     * @return String
     */
    public static String getTypeName(String type, String value) {
        if(GlobalConstant.DICT_LIST != null){
            for (BaseBean dict: GlobalConstant.DICT_LIST) {
                if (dict.getPcode().equals(type) && dict.getCode().equals(value)) {
                    return dict.getName();
                }
            }
        }
        return value;
    }
	/**
	 * Author:shanzhitong
     * Create At:2010-06-22
     * Description: [根据省份代码获取市级下拉列表 pcode省份代码 cityCode 只显示登录人的市 可空]
     * @return String
     */
    public static List<RegionsBean> getCityList(String pcode, String cityCode) {
    	List<RegionsBean> list = new ArrayList<RegionsBean>();
    	if(GlobalConstant.CITY_LIST != null && pcode != null && !"".equals(pcode.trim())){
    		for(RegionsBean dict:GlobalConstant.CITY_LIST){
    			if(pcode.equals(dict.getPcode())){
    				if(cityCode == null || "".equals(cityCode) ){
    					list.add(dict);
    				}else if(cityCode.equals(dict.getCode())){
    					list.add(dict);
    				}
    			}
    		}
    	}
		return list;
    }
    
    /**
     * Author:shanzhitong
     * Create At:2010-06-22
     * Description: [根据省份代码获取市级下拉列表 pcode省份代码 cityCode 只显示登录人的市 可空]
     * @return String
     */
    public static List<RegionsBean> getCityList(String cityCode) {
        List<RegionsBean> list = new ArrayList<RegionsBean>();
        String pcode = GlobalConstant.SYSTEM_DEFAULT_CITY;
        if(GlobalConstant.CITY_LIST != null && pcode != null && !"".equals(pcode.trim())){
            for(RegionsBean dict:GlobalConstant.CITY_LIST){
                if(pcode.equals(dict.getPcode())){
                    if(cityCode == null || "".equals(cityCode) ){
                        list.add(dict);
                    }else if(cityCode.equals(dict.getCode())){
                        list.add(dict);
                    }
                }
            }
        }
        return list;
    }
    
    /**
     * Author:shanzhitong
     * Create At:2017-05-07
     * Description: [根据城市code获取name]
     * @return String
     */
    public static String getCityName(String cityCode) {
        if(GlobalConstant.CITY_LIST != null){
            for(RegionsBean dict:GlobalConstant.CITY_LIST){
                if (dict.getCode().equals(cityCode)) {
                    return dict.getName();
                }
            }
        }
        return cityCode;
    }

    /**
     * Author:shanzhitong
     * Create At:2017-05-07
     * Description: [根据城市code获取级联关系]
     * @return String
     */
    public static String getCityPath(String cityCode) {
        if(GlobalConstant.CITY_LIST != null){
            for(RegionsBean dict:GlobalConstant.CITY_LIST){
                if (dict.getCode().equals(cityCode)) {
                    return dict.getPath();
                }
            }
        }
        return cityCode;
    }
}